----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 14315 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Frost Shot"
SPELL.m_sToolTip =	[[You launch a frost shot
					at the target, dealing 
					moderate damage and slowing
					the target for 3 seconds.]]
SPELL.m_sIcon = "devin/blackbetty/spells/ranger/frostshot.png"
SPELL.m_iCoolDown = 12
SPELL.m_iManaCost = 0
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_RANGEDAMAGE
SPELL.m_sUsedBy = "class_ranger"

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	
	print("Casted "..self.m_sName.."!")
	
	local range = self.m_iRange
		
	if(target && target:IsValid() && target != pl) then
		ParticleEffectAttach( "impact_frostbig", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
		if(pl:GetPos():Distance(target:GetPos()) < range)then
			self:Effect(pl, target)
			--self:ApplySpellMods(self, pl, target)
		end
	end
end

function SPELL:Effect(pl, target)

	local weapon = pl:GetWeapon("weapon_all")
	
	pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_CROSSBOW)
	pl:EmitSound("devin/blackbetty/weapons/bow/BowRelease01.wav", 150, 100+math.random(-10,10))
	pl:EmitSound("devin/blackbetty/weapons/castsounds/IceCast.wav", 150, 130+math.random(10,20))
	if(SERVER)then
		local myhitdelay = ((pl:GetPos() - target:GetPos()):Length()/2200)
		LaunchProjectile(pl, target, 0, "pummel_hit", "", "frostshot", "devin/blackbetty/weapons/travelsounds/IceMissileLoop.wav", myhitdelay, 2400, "models/crossbow_bolt.mdl")
		timer.Simple(myhitdelay, function()
			self:DealDamage(weapon.MinWeaponDamage*2, weapon.MaxWeaponDamage*2, pl, target, DMG_DROWN)
			target:EmitSound("devin/blackbetty/weapons/bow/ArrowHit0"..math.random(1,3)..".wav", 100, 100+math.random(-10,10))
			pl:EmitSound("devin/blackbetty/weapons/hit/Ice1.wav", 150, 130+math.random(10,20))
			ParticleEffect( "impact_frostbig", target:GetPos() + Vector(0, 0, 32), Angle(0,0,0), pl )
			ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 45), Angle(0,0,0), target )
			if(target:IsPlayer())then
				local b = AddEffect(target, 1, "NetShot", 0.7, 1, 1.5, 1)
			end
		end)
	end
end




